load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("//bazel:flags.bzl", "CPP_FLAGS", "MAPLIBRE_FLAGS")

cc_library(
    name = "testutils",
    hdrs = glob(["include/mbgl/test/*.hpp"]),
    strip_include_prefix = "include",
    deps = [
        "@googletest//:gtest",
    ],
)

cc_library(
    name = "testlib",
    srcs = select({
        "@platforms//os:ios": glob(["src/mbgl/test/*.cpp"]),
        "//conditions:default": glob(
            ["src/mbgl/test/*.cpp"],
            exclude = ["src/mbgl/test/http_server.cpp"],
        ),
    }) + [
        "include/mbgl/test.hpp",
    ],
    hdrs = glob([
        "src/mbgl/test/*.hpp",
    ]),
    copts = CPP_FLAGS + MAPLIBRE_FLAGS + select({
        "@platforms//os:ios": ["-DUSE_CPP_TEST_SERVER"],
        "//conditions:default": [],
    }),
    includes = [
        "include",
    ],
    strip_include_prefix = "src",
    visibility = [
        "//platform/ios/test/core:__pkg__",
    ],
    deps = [
        "testutils",
        "//:mbgl-core",
    ] + select({
        "@platforms//os:ios": ["//vendor:httplib"],
        "//conditions:default": [],
    }),
)

cc_library(
    name = "tests",
    srcs = glob(
        [
            "**/*.test.cpp",
        ],
        exclude = ["renderer/wgsl_preprocessor.test.cpp"],
    ) + select({
        "//:webgpu_renderer": ["renderer/wgsl_preprocessor.test.cpp"],
        "//conditions:default": [],
    }),
    copts = CPP_FLAGS + MAPLIBRE_FLAGS,
    visibility = [
        "//platform/ios/test/core:__pkg__",
    ],
    deps = [
        "testlib",
        "testutils",
        "//:mbgl-core",
        "//platform/default:mbgl-default",
        "@googletest//:gtest_main",
    ],
    alwayslink = True,
)

filegroup(
    name = "fixtures",
    srcs = glob(
        ["fixtures/**/*"],
    ),
    visibility = [
        "//platform/ios/test/core:__pkg__",
    ],
)

cc_test(
    name = "core",
    args = [
        "--gtest_filter=-Map.StyleNetworkErrorRetry:Map.StyleNotFound:MainResourceLoader.CachedResourceLowPriority",
    ],
    data = glob(["fixtures/**/*"]) + [
        "//:scripts/style-spec-reference/v8.json",
    ],
    tags = ["no-sandbox"],
    deps = [
        "tests",
        "//platform/linux:impl",
    ],
)
